package com.xbh.management.security;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.web.authentication.WebAuthenticationDetails;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: management-center
 * @description: 获取用户登录时携带的额外信息
 * WebAuthenticationDetails: 该类提供了获取用户登录时携带的额外信息的功能，默认提供了 remoteAddress 与 sessionId 信息。
 * 自定义了WebAuthenticationDetails，我i们还需要将其放入 AuthenticationDetailsSource 中来替换原本的 WebAuthenticationDetails ，
 * 因此还得实现自定义 AuthenticationDetailsSource ：
 * 类内容将原本的 WebAuthenticationDetails 替换为了我们的 CustomWebAuthenticationDetails。
 * 然后我们将 CustomAuthenticationDetailsSource 注入Spring Security中，替换掉默认的 AuthenticationDetailsSource。
 * 修改 WebSecurityConfig
 * @author: 许宝华
 * @create: 2021-10-07 18:04
 */

public class UserWebAuthenticationDetails extends WebAuthenticationDetails {

    private static Logger log = LoggerFactory.getLogger(UserWebAuthenticationDetails.class);

    private static final long serialVersionUID = 6975601077710753878L;

    private final String code;

    /**
     * @param request that the authentication request was received from
     */

    public UserWebAuthenticationDetails(HttpServletRequest request) {
        super(request);
        code=request.getParameter("code");
        log.info("进入到了获取验证码的过滤器-->WebAuthenticationDetails,获取到的验证码-->"+code);

    }



    public String getCode() {
        return code;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(super.toString()).append("; code: ").append(this.getCode());
        return sb.toString();
    }
}
